import Vue from 'vue'
import App from './App.vue'
import router from './router'
import store from './store/index'
import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import { Message } from "element-ui";
import axios from 'axios';

Vue.config.productionTip = false
Vue.use(ElementUI);

//全局注册数据请求方法
Vue.prototype.$http=axios

axios.defaults.baseURL = 'http://1.14.48.193:8080/';
//路由导航守卫
router.beforeEach((to, from, next) => {
  
  if (to.meta.requiresAuth) {
    // 对路由进行验证
    if (sessionStorage.getItem('token') == null || sessionStorage.getItem('token') === '') { // 未登录
      // 未登录则跳转到登陆界面
      Message.error("检测到您还未登录，请登录后操作！");
      next({ path: '/login' })
    } else {
      next() // 正常跳转到你设置好的页面
    }
  } else {
    next()
  }
})

new Vue({
  router,
  store,
  render: h => h(App)
}).$mount('#app')
